
package com.eascs.web.o2o.scheduler.test;

import javax.inject.Inject;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.common.util.StopWatch;
import com.eascs.site.controller.BaseRestController;
import com.eascs.web.o2o.scheduler.entity.CustomerBasicInfo;
import com.eascs.web.o2o.scheduler.service.CrmService;
import com.eascs.web.o2o.scheduler.service.CustomerShopInfoService;
import com.eascs.web.o2o.scheduler.service.SynchroCrm;

@RestController
public class CrmController extends BaseRestController {
	protected final Logger logger = LoggerFactory.getLogger(getClass());

	@Inject
	CrmService crmService;
	@Inject
	SynchroCrm			synchroCrm;
	@Inject
	CustomerShopInfoService customerShopInfoService;
	
	
	
	/**
	 * 同步客户基本信息
	 */
	@RequestMapping(value = "/crm/saveCustomerInfo")
	public void saveCustomerInfo() {
		StopWatch stopWatch = new StopWatch();
		synchroCrm.saveCustomerInfo();
		logger.info("[CRM]客户基本信息同步结束，共耗时：[{}]分", stopWatch.elapsedTime()/60000);
	}

	
	@RequestMapping(value = "/crm/updateName")
	public void updateName (){
		StopWatch stopWatch = new StopWatch();
		// 5.更新配偶姓名拼音、姓、名字
		try {
			crmService.loadData2("select * from customer_basic_info where customer_family_name is null",
					CustomerBasicInfo.class);
			logger.info("[CRM]更新配偶姓名拼音、姓、名字结束......");
		} catch (Exception e) {
			logger.error("[CRM]Error：更新配偶姓名拼音、姓、名字失败！！！");
			e.printStackTrace();
		}
		logger.info("[CRM]客户基本信息同步结束，共耗时：[{}]分", stopWatch.elapsedTime() / 60000);
	}
	
	
	@RequestMapping(value = "/crm/synchcroCrm")
	public void synchcroCrm (){
		StopWatch stopWatch = new StopWatch();
		synchroCrm.saveCustomerInfo();
		logger.info("生产环境crm同步结束，共耗时：[{}]分", stopWatch.elapsedTime() / 60000);
	}
	
	
	
	/**
	 * 同步crm sd数据（近3天）
	 */
	@RequestMapping(value = "/o2o/scheduler/crm/synch/sd")
	public void crmSD() {
		synchroCrm.saveData();
	}

	/**
	 * 更新code为空的用户的code
	 */
	@RequestMapping(value = "/o2o/scheduler/crm/update/code")
	public void updateCrmCustomerCode() {
		synchroCrm.updateCustomerCodeOnly();
	}

	/**
	 * 更新code为空的用户的code
	 */
	@RequestMapping(value = "/o2o/scheduler/crm/update/code/{id}")
	public void updateCrmCustomerCodeById(@PathVariable String id) {
		synchroCrm.updateCustomerCodeById(id);
	}
	/**
	 * 贷中新系统日增
	 */
	@RequestMapping(value = "/o2o/scheduler/updateCustomerInfo")
	public void updateCustomerInfo() {
		synchroCrm.updateCustomerInfo();
	}

	@RequestMapping(value = "/o2o/scheduler/saveAllCustomerShopInfo")
	public void saveAllCustomerShopInfo() {
		customerShopInfoService.saveAllCustomerShopInfo();
	}
	
	@RequestMapping(value = "/o2o/scheduler/saveCustomerShopInfo")
	public void saveCustomerShopInfo() {
		customerShopInfoService.saveCustomerShopInfo();
	}
	
	
	
}